// FacebookSessionCreatingEventArgs.cs
// Facebook/FrameworkWeb/Web
// Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
//

using System;
using Facebook.Service.Core;

namespace Facebook.Web {

    /// <summary>
    /// The event object associated with the SessionCreating event.
    /// </summary>
    public sealed class FacebookSessionCreatingEventArgs : EventArgs {

        private string _sessionKey;
        private string _userID;
        private string _pageUserID;

        internal string PageUserID {
            get {
                return _pageUserID;
            }
        }

        internal string SessionKey {
            get {
                return _sessionKey;
            }
        }

        internal string UserID {
            get {
                return _userID;
            }
        }

        /// <summary>
        /// Allows the event handler to provide session information of an already
        /// established infinite session to use. This is useful if the page is
        /// being browsed externally, i.e. outside of Facebook, and the page
        /// wants to access Facebook APIs in the context of an infinite session.
        /// </summary>
        /// <param name="sessionKey">The session key of the infinite session.</param>
        /// <param name="userID">The ID of the user associated with the infinite session.</param>
        public void SetInfiniteSession(string sessionKey, string userID) {
            SetInfiniteSession(sessionKey, userID, null);
        }

        /// <summary>
        /// Allows the event handler to provide session information of an already
        /// established infinite session to use. This is useful if the page is
        /// being browsed externally, i.e. outside of Facebook, and the page
        /// wants to access Facebook APIs in the context of an infinite session.
        /// </summary>
        /// <param name="sessionKey">The session key of the infinite session.</param>
        /// <param name="userID">The ID of the user associated with the infinite session. If the session is associated with a page, this is the page ID.</param>
        /// <param name="pageUserID">The ID of the user browsing the page if the session is associated with a page.</param>
        public void SetInfiniteSession(string sessionKey, string userID, string pageUserID) {
            if (String.IsNullOrEmpty(sessionKey)) {
                throw new ArgumentNullException("sessionKey");
            }
            if (String.IsNullOrEmpty(userID)) {
                throw new ArgumentNullException("userID");
            }

            _sessionKey = sessionKey;
            _userID = userID;
            _pageUserID = pageUserID;
        }
    }

    /// <summary>
    /// The event handler signature used to handle the SessionCreating event.
    /// </summary>
    /// <param name="sender">The object raising the event.</param>
    /// <param name="e">The event object associated with the event.</param>
    public delegate void FacebookSessionCreatingEventHandler(object sender, FacebookSessionCreatingEventArgs e);
}
